// components/toast/toast.js
import { server } from "../../utils/config.js";

const _app = getApp();
let TimerDuration;

Component({

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        server: server,
        isShow: false,
        message: "成功~",
        icon: "success",
        duration: 2000
    },

    /**
     * 组件的方法列表
     */
    methods: {

        /**
         * 展示toast
         */
        showToast(message = "成功~", icon = 'success', duration = 2000) {
            let that = this;
            this.setData({
                isShow: true,
                message: message,
                icon: icon,
                duration: duration
            })
            TimerDuration = setTimeout(function() {
                //隐藏
                that.hideToast();
            }, this.data.duration);
        },

        /**
         * 隐藏toast
         */
        hideToast() {
            this.setData({
                isShow: false
            });
        },
    }
})